efform_onload = function() {
	if ($('#flag').val() == 1) {
		document.getElementById('ef_region_inqu').style.display = "none";
		efbutton.setButtonStatus("insert", false);
		efbutton.setButtonStatus("update", false);
		efbutton.setButtonStatus("delete", false);
		efbutton.setButtonStatus("report", false);
	}
};  
//查询
button_query_onclick = function() {
	efgrid.submitInqu("ef_grid_result", "ZM", "ZMCK32", "query");
};
// 新增
button_insert_onclick = function() {
	if (isSelected("ef_grid_result") == 0)
		return;
	efgrid.submitForm("ef_grid_result", "ZM", "ZMCK32", "insert", true);
};
// 修改
button_update_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能对草拟的记录进行修改！");
			return;
		}
	}
	efgrid.submitForm("ef_grid_result", "ZM", "ZMCK32", "update", true);
};
// 删除
button_delete_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能对草拟的记录进行删除！");
			return;
		}
	}

	EFConfirm('你确认要删除吗?', '确认框',
			function(r) {
				if (r)
					efgrid.submitForm("ef_grid_result", "ZM", "ZMCK32",
							"delete", true);
			});
};
// 上报
button_report_onclick = function() {
	var grid = isSelected("ef_grid_result");
	if (grid == 0)
		return;

	var rows = grid.getCheckedRows();
	if (rows.length > 1) {
		EFAlert("一次只能上报一条记录！", "警告");
		return;
	}
	for (var i = 0; i < rows.length; i++) {
		if (grid.getCellValueByColumnName(rows[i], "fdStatus") != "草拟") {
			EFAlert("只能上报草拟状态的记录！", "警告");
			return;
		}
		if (grid.getCellValueByColumnName(rows[i], "fdKeyId") == "") {
			EFAlert("该记录不存在，请先新增后再上报！", "警告");
			return;
		}
	}

	EFConfirm('确认要上报吗?', '确认框',
			function(r) {
				if (r)
					efgrid.submitForm("ef_grid_result", "ZM", "ZMCK32",
							"report", true);
			});
};
efgrid_afterAddNewRow = function(grid_id) {
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();
	if (grid_id == "ef_grid_result") {

		var fdDepartment = $('#fdDepartment').val();
		var day = getNowDate(); // 当前日期
		var time = getNowDateTime();// 当前时间

		for (var i = 0; i < rows.length; i++) {
			grid.getBlockData().setCell(rows[i], "fdKeyId", "");
			grid.getBlockData().setCell(rows[i], "fdStatus", "草拟"); // 状态
			grid.getBlockData().setCell(rows[i], "fdCurrentDate", day);// 当前日期
			grid.getBlockData().setCell(rows[i], "fdDepartment", fdDepartment);// 责任单位（矿井名称）
			grid.getBlockData().setCell(rows[i], "fdFlzzJyrq", day);// 校验日期
			grid.getBlockData().setCell(rows[i], "fdFhssTime", time);// 检查时间
		}
	}
};
//打印
button_print_onclick = function() {
	var grid = efgrid.getGridObject("ef_grid_result");
	var row_index=grid.getCurrentRowIndex();
	if(row_index<0){
		EFAlert("请先点击一下选中项目信息后打印！");
		return;
	}
	var fdFhssTime=grid.getCellValueByColumnName(row_index,"fdFhssTime");
	// 取报表参数
	var param = [];
	param.YEAR =fdFhssTime.substr(0,4);
	var reportEname = "ZM_CH_FLZZ";
	try {
		previewReport(reportEname,param);
	} catch (e) {
		alert("控件加载失败，请确认控件是否正确安装并将本网站设为信任地址");
	}
}
button_upload_onclick=function(){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return;
	var row_index=grid.getCheckedRowCount();
	var row=grid.getCheckedRows();
	if(row_index>1){
		EFAlert("只能选中一条项目信息后上传！");
		return;
	}
	var docId=grid.getCellValueByColumnName(row,"fdDocid");
	if(!isAvailable(docId)) {
		EFAlert("未指定文档号！", "系统警告");
		return false;
	}
	var url = "DispatchAction.do?efFormEname=EUAF3501";
		url = url + "&inqu_status-0-code=zm.cp";
	
	if(grid.getCellValueByColumnName(row,"fdStatus")!="草拟")
	{
		url = url + "&editFlag=0";
	}else{
		url = url + "&editFlag=1";
	}
	url = url + "&inqu_status-0-docId="+docId+"&time=" + new Date().getTime();
	
	EFColorbox({href:url,title:"附件管理",width:"80%", height:"80%", iframe:true});
} 